<?php
include("account.php");

$user_id = GetLoginId($_COOKIE['t']);

if ($user_id && $user_id > 0) {
  $res_word = "用户已经登录";
  header('Location: ' . $URL_MY_PAGE);
}
?>
<?php
$page_title = "用户注册";
include("../header.php");
?>
<script src="/js/jquery.ui.draggable.js" type="text/javascript"></script>
<script src="/js/jquery.alerts.js" type="text/javascript"></script>
<link href="/css/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" />
<style type="text/css">
label.account_input_name {
display:inline-block;line-height:30px;width:100px;
}
input.account_input {
vertical-align: middle;margin:-6px 0 0 0px;padding: 6px 4px 6px;width:216px;font-size:90%;border:1px solid #cbc;
}

span.account_input_desc {
display:none;
font-size:12px;
font-weight:normal;
margin-left:30px;
height:36px;
border-right: 1px solid #F1E562;
background:url("http://www.jztzp.com/img/jztzp-account-bg.png") no-repeat scroll 4px -180px transparent;;
line-height: 36px;
padding-left: 12px;
padding-right: 12px;
}
input.account_input_submit{
  padding:4px 2px;
  cursor:pointer;
  cursor:hand;
  font-weight:bold;
  font-size:18px;
  height:30px;
  width:86px;
  text-align:center;
  border: 1px solid #CCCCCC;
  color: #183D5C;
  background-color:#F6F6F6;
}

</style>
<div class="container">
<div style="line-height:29px; font-size:18px;margin:40px 70px 440px">
<p>
<label class="account_input_name">邮箱:</label> <input class="account_input" id="email_input" name="email" type="text"/> <span id="email_input_desc" class="account_input_desc">使用邮箱</span>
</p>
<p>
<label class="account_input_name">昵称:</label> <input class="account_input" id="nick_input" name="nick" type="text"/>
</p>
<p>
<label class="account_input_name">密码:</label> <input class="account_input" id="pwd_input" name="uk" type="password"/>
</p>
<p>
<label class="account_input_name">确认密码:</label> <input class="account_input" id="pwd_input2" name="uk" type="password"/>
</p>
<input id="register_button" class="account_input_submit" type="button" value="注册"/> &nbsp; <a style="font-size:70%;" href="<?php echo $URL_LOGIN_PAGE ?>">登录</a>

</div>
</div>

<script type="text/javascript">
function ValidateEmail(email) { 
  var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  return re.test(email);
}

$('#email_input').change(
  function(event) {
    var email = $('#email_input', $(this).parent()).val();
    if (ValidateEmail(email)) {
      $('#email_input', $(this).parent()).css("border", "1px solid green");
    } else {
      $('#email_input', $(this).parent()).css("border", "1px solid red");
    }
  }
);

$('#nick_input').change(
  function(event) {
    var nick = $('#nick_input', $(this).parent()).val();
    if (!nick || nick.length <= 0) {
      $('#nick_input').css("border", "1px solid red");
    } else {
      $('#nick_input').css("border", "1px solid green");
    }
  }
);

function UpdatePasswordStyle() {
    var pwd1 = $('#pwd_input').val();
    var pwd2 = $('#pwd_input2').val();
    if (!pwd1 || pwd1.length <= 5) {
      $('#pwd_input').css("border", "1px solid red");
      $('#pwd_input2').css("border", "1px solid red");
      return;
    }

    if (pwd1.length > 5 && pwd1 == pwd2) {
      $('#pwd_input').css("border", "1px solid green");
      $('#pwd_input2').css("border", "1px solid green");
    } else {
      $('#pwd_input').css("border", "1px solid red");
      $('#pwd_input2').css("border", "1px solid red");
    }
}

$('#pwd_input').keyup(UpdatePasswordStyle);

$('#pwd_input2').keyup(UpdatePasswordStyle);

$('#email_input').change(
  function(event) {
    var email = $('#email_input', $(this).parent()).val();
    if (ValidateEmail(email)) {
      $('#email_input', $(this).parent()).css("border", "1px solid green");
    } else {
      $('#email_input', $(this).parent()).css("border", "1px solid red");
    }
  }
);

$('#register_button')
.hover(
  function(event) {
    $(this).css('background-color', '#FDF5CE');
  },
  function(event) {
    $(this).css('background-color', '#F6F6F6');
  }
)
.click(
  function(event) {
    var email = $('#email_input').val();
    if (ValidateEmail(email)) {
      $('#email_input', $(this).parent()).css("border", "1px solid green");
    } else {
      alert('请输入正确的邮箱地址');
      $('#email_input', $(this).parent()).css("border", "1px solid red").focus();
      return;
    }

    var nick = $('#nick_input').val();
    if (!nick || nick.length <= 0) {
      alert('昵称不能为空');
      $('#nick_input').css("border", "1px solid red").focus();
      return;
    }
    
    var pwd1 = $('#pwd_input').val();
    var pwd2 = $('#pwd_input2').val();
    if (!pwd1 || pwd1.length <= 0) {
      alert('密码不能为空');
      $('#pwd_input').css("border", "1px solid red").focus();
      return;
    }

    if (pwd1.length <= 5) {
      alert('密码长度过短');
      $('#pwd_input').css("border", "1px solid red").focus();
      return;
    }

    if (pwd1 != pwd2) {
      alert('两次密码输入必须相同');
      $('#pwd_input').css("border", "1px solid red").focus();
      $('#pwd_input2').css("border", "1px solid red");
      return;
    }

    $.ajax('/account/create.php', {
      'data' : 'email=' + email + '&nick=' + nick + '&uk=' + pwd1,
      'type' : 'POST',
      'success' : function(rsp_txt){
        $.globalEval('var o = ' + rsp_txt);
        if (o.code == 0) {
          jAlert('注册成功! 请<a href="/account/login.php">登录</a>', '注册成功');
        } else {
          alert('注册失败：' + o.desc);
        }
      },
      'error' : function() {
        alert('网络错误, 请稍后重试');
      }
    });
  }
);


</script>
<?php
include("../footer.php");
?>

